package blt.app_core.api.base.callback;

import java.util.List;

import blt.app_core.api.base.CoreManager;
import blt.app_core.api.base.IBaseApi;
import blt.app_core.api.base.bean.OAuth;
import blt.app_core.api.base.bean.State;
import retrofit2.Call;
import retrofit2.Response;

/**
 * data为数组
 * Created by xgp on 2017/6/20.
 */

public abstract class ComBack<T> extends BaseCallback<OAuth<T>> {
    @Override
    public void onResponse(Call<OAuth<T>> call, Response<OAuth<T>> response) {
        super.onResponse(call, response);
        OAuth oAuth = response.body();
        if (oAuth == null) {
            return;
        }
        if (oAuth.errcode != SUCCESS) {
            CoreManager.notifyClients(IBaseApi.class, IBaseApi.ERROR_MSG, oAuth.errmsg);
        } else {
            List<T> data = response.body().data;
            onSuccess(data);
        }
    }


    @Override
    public void onFailure(Call<OAuth<T>> call, Throwable t) {
        super.onFailure(call, t);
        CoreManager.notifyClients(IBaseApi.class, IBaseApi.ERROR_MSG, FAILED);
    }

    protected abstract void onSuccess(List<T> data);

    //    @Override
//    public void onResponse(Call<OAuth> call, Response<OAuth> response) {
//        super.onResponse(call, response);
//        OAuth oAuth = response.body();
//        if (oAuth.errcode != SUCCESS) {
//            CoreManager.notifyClients(IBaseApi.class, IBaseApi.ERROR_MSG, oAuth.errmsg);
//        } else {
//            onSuccess(response.body());
//        }
//    }
//


}
